//
//  MKEnvObserverCenter.m
//  LNUniversal
//
//  Created by liu nian on 21/1/25.
//  Copyright (c) 2015年 Liu Nian site:http://iliunian.com. All rights reserved.
//

#import "MKEnvObserverCenter.h"

@interface MKEnvObserverCenter ()
@property (nonatomic, strong) NSMutableArray *observers;
@end
@implementation MKEnvObserverCenter

- (id)init {
    self = [super init];
    if (self) {
        _observers = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return self;
}

- (void)addEnvObserver:(id)observer {
    if (observer == nil) {
        return;
    }
    for (MKObserver * ob in _observers) {
        if (ob.observer == observer) {
            return;
        }
    }
    MKObserver * ob = [MKObserver createWithObejct:observer];
    [_observers addObject:ob];
}

- (void)removeEnvObserver:(id)observer {
    for (NSInteger i = 0; i < [_observers count]; i++) {
        MKObserver * ob = [_observers objectAtIndex:i];
        if (ob.observer == observer) {
            [_observers removeObjectAtIndex:i];
            return;
        }
    }
}

- (void)noticeObervers:(SEL)selector {
    [_observers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        MKObserver * observer = obj;
        [observer noticeOberver:selector];
    }];
}

- (void)noticeObervers:(SEL)selector withObject:(id)object {
    [_observers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        MKObserver * observer = obj;
        [observer noticeOberver:selector withObject:object];
    }];
}

- (void)noticeObervers:(SEL)selector withObject:(id)object1 withObject:(id)object2 {
    [_observers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        MKObserver * observer = obj;
        [observer noticeOberver:selector withObject:object1 withObject:object2];
    }];
}

@end
